<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Trade extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->checkAdmin($this->session->userdata('admin_id'));
        $this->data['controller'] = 'trade';
        $this->load->model('Mtrade');
    }
    
    public function index()
    {
        $this->load->library('pagination');
        $config['per_page'] = $this->data['_per_page'] = 10;
        $this->data['page'] = $this->data['page_current'] = $this->getParamUri(3,3);
        $offset = (($this->getParamUri(3,3) - 1) * $config['per_page']) > 0 ? (($this->getParamUri(3,3) - 1) * $config['per_page']) : 0;
        $data = $this->Mtrade->getIndex($config['per_page'],$offset);
        $config['base_url'] = base_url($this->uri->segment(1).'/'.$this->uri->segment(2).'/');
        $config['total_rows'] = $data['count'];
        $config['uri_segment'] = 3;
        $config['uri_segment_page'] = $this->getParamUri(3,3);
        $config['suffix'] = '.html';
        $config['use_page_numbers'] = TRUE;
        $this->pagination->initialize($config);
        $this->data['data'] = $data['data'];
        
        $this->data['action'] = 'index';
        $this->load->view('template/layout', $this->data);
    }
    
    public function searchajax()
    {
        $key = $this->getParamString('keyword');
        
        $this->data['data'] = $this->Mtrade->getSearchAjax($key);
        $this->data['action'] = 'searchajax';
        $this->load->view('template/trade/searchajax', $this->data);
    } 
}